package com.ruan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruan.mapper.LeaveTypeMapper;
import com.ruan.mapper.TripTypeMapper;
import com.ruan.pojo.LeaveType;
import com.ruan.pojo.TripType;
import com.ruan.service.LeaveTypeService;
import com.ruan.service.TripTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class TripTypeServiceImpl extends ServiceImpl<TripTypeMapper, TripType> implements TripTypeService {

    @Resource
    private TripTypeMapper tripTypeMapper;

    /**
     * 获得出差方式列表
     * @return
     */
    @Override
    public List<TripType> getTripType() {
        List<TripType> tripTypeList = tripTypeMapper.selectList(null);
        return tripTypeList;
    }

    /**
     * 禁用出差方式
     * @param id 出差方式id
     */
    @Override
    public void stopType(Integer id) {
        TripType tripType = tripTypeMapper.selectById(id);
        tripType.setStatus("禁用");
        tripTypeMapper.updateById(tripType);
    }

    /**
     * 启用出差方式
     * @param id 出差方式id
     */
    @Override
    public void startType(Integer id) {
        TripType tripType = tripTypeMapper.selectById(id);
        tripType.setStatus("启用");
        tripTypeMapper.updateById(tripType);
    }

    /**
     * 获得可用出差方式列表
     * @return
     */
    @Override
    public List<TripType> getUsingTripType() {
        LambdaQueryWrapper<TripType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TripType::getStatus,"启用");
        List<TripType> tripTypeList = tripTypeMapper.selectList(queryWrapper);
        return tripTypeList;
    }
}
